using System;
using CUtil;
using System.Collections;

namespace CStock
{
	/// <summary>
	/// Summary description for TradeSystem.
	/// </summary>
	/// 
	
	public class TradeSystemFactory : Factory, ITradeSystemFactory
	{
        ITradeSystem tradeSystem;

        public TradeSystemFactory()
        {
            this.stockObjectBase = new TradeSystem();
            stockObjectBase.ID = CUtil.TradeSystemFiles.Trade.ToString();
            tradeSystem = this.stockObjectBase as ITradeSystem;

        }
     
       
        public override bool Create_TestData()
        {
            base.Create_TestData();

            return Create_Default();

        }
        public override bool Create_Default()
        {
            base.Create_Default();
            tradeSystem.Value_Money = 10000;
            tradeSystem.PortfolioID = "Bonds";
            tradeSystem.ShareID = "US10Years";

            tradeSystem.BuyConditions = new CStock.TradeCondition[0];
            tradeSystem.SellConditions = new CStock.TradeCondition[0];

            TradeCondition tc = new TradeCondition();

            tc.IndicatorName = "MovingAverageLinearE";
            tc.Period = 2;
            tc.AndOrOr = "And";
            tc.BuyOrSell = "Buy";
            tc.GreaterOrLess = ">";
            tc.ThresholdValueOrIndicator = "1";
            tc.OptimizeEnd = 4;
            tc.OptimizeStart = 0;
            tc.OptimizeStep = 2;


            tradeSystem.AddBuyCondition(tc);

            tc = new TradeCondition();

            tc.IndicatorName = "MovingAverageLinearE";
            tc.Period = 2;
            tc.AndOrOr = "And";
            tc.BuyOrSell = "Sell";
            tc.GreaterOrLess = "<";
            tc.ThresholdValueOrIndicator = "-1";

            tc.OptimizeEnd = 0;
            tc.OptimizeStart = -4;
            tc.OptimizeStep = 2;


            
            tradeSystem.AddSellCondition(tc);

           
            
            return true;


        }

        /// <summary>
        /// attention - new object variable for dataClass!!
        /// </summary>
        /// <returns></returns>
        public override bool DeSerialize()
        {
            if (base.DeSerialize())
            {
                this.tradeSystem = this.stockObjectBase as ITradeSystem;


                return true;
            }

            return false;

        }
       
        

	}
}
